const app = getApp(),url = app.globalData.url;
import util from '../../utils/util'
Page({

  /**
   * 页面的初始数据
   */
  data: {
		// 倒计时参数
		mobile:'',
		code:'',
		timeStart:60, //倒计时初始值
    timeCur:null, //当前倒计时显示值
    ifTimeIn:false, //是否倒计时中
		success:false,
		truef:true,
		eetruef:true,
	},
	
		caonima(){
			this.setData({
				truef:!this.data.truef
			})
		},
		caonimass(){
			this.setData({
				eetruef:!this.data.eetruef
			})
		},
	// form: {
	// 	resource: '1',
	// 	account: '',
	// 	password: '',
	// 	password2: ''
	// },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
	// 获取手机号
	setMobile(e){
    let that = this
		console.log(e.detail.value);
		that.setData({
      mobile : e.detail.value.replace(/\s+/g,""),//去空格
      
      // success:true,
		});
	},
	// 验证码
  setCode(e){
    let that = this
		that.setData({
      code : e.detail.value.replace(/\s+/g,""),
		});
	},
	// 新密码
	oldpass(e){
    let that = this
		console.log(e.detail.value);
		that.setData({
      oldpass : e.detail.value.replace(/\s+/g,""),//去空格
      success:true,
		});
  },
	// 确认新密码
  newpass(e){
    let that = this
		console.log(e.detail.value);
		that.setData({
      newpass : e.detail.value.replace(/\s+/g,""),//去空格
      // success:true,
		});
  },
  // 倒计时
	setTime(){
		let timeCur = this.data.timeCur - 1;
		// console.log(timeCur);
		if(timeCur < 0){
			clearInterval(this.data.timer);
			this.setData({
				ifTimeIn:false
			});
			return false;
		}
		this.setData({
			timeCur : timeCur
		});
  },
  // 获取验证码
	getMobileVerify(){
		var that = this
		if(!that.data.mobile){
			wx.showModal({
				title: '友情提示',
				content: '请输入手机号',
				showCancel: false,
			});
			return false
    }
		if(!/^1\d{10}$/.test(that.data.mobile)){
			wx.showModal({
				title: '友情提示',
				content: '请输入正确的手机号',
				showCancel: false,
			});
			return false;
		}
		wx.showLoading({
		  title: "发送中",
		  mask: true
		});
		//enterprise/sendSmsMessage
		wx.request({
      url:url+'enterprise/sendSmsMessage',
      method: "GET",
      data:{
				mobile_no:that.data.mobile
			},
      success:function(res){
        console.log("code",res);
        var ret = res.data
        if(ret.code == 200){
					/* ----请求后台发送验证码成功---- */
					// 执行倒计时
					that.setData({
						timeCur : that.data.timeStart,
						timer : setInterval(that.setTime,1000),
						ifTimeIn : true,
						success:true,
						
						// ifSendMobileVerify : true
					});
					/* ----请求后台发送验证码成功---- */
					// that.setData({listdata:ret.data.content})
					wx.hideLoading();
					wx.showToast({
            title: ret.msg,
            icon:'none'
					})
        }else{
          wx.showToast({
            title: ret.msg,
            icon:'none'
					})
					wx.hideLoading();
        }
      }
    })
	},
  // 确定提交
	bindDo(){
		var that = this
		// var phone = that.data.mobile
		var passold = that.data.oldpass
		var newpass = that.data.newpass
		that.setData({success:false})
		// if(phone == ''){
		// 	wx.showToast({
		// 		title: '请输入您的账号',
		// 		icon:'none',
		// 	})
		// 	that.setData({success:true})
		// 	return false
		// }
			
		if(!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/.test(passold)){
			wx.showToast({
				title: '请输入6-16位数字字母组合',
				icon:'none',
			})
			that.setData({success:true})
			return false
		}

		if(passold != newpass){
			wx.showModal({
				title: '友情提示',
				content: '两次密码输入有误',
				showCancel: false,
			});
			that.setData({success:true})
			return false;
		}
		

    var mima = util.strEncode(passold)



		var uid = wx.getStorageSync('user_massage')
		wx.request({
			url:url+'user/updateXcxPassword',
			method: "put",
			data:{
				// account:phone,
				password:mima,
				id:uid.id,
			},
			success:function(resh){
				console.log("确定提交",resh);
				wx.showToast({
					title: '成功',
					icon: 'success',
					mask: true,
					duration: 1500
				});
				setTimeout(function(){
					wx.navigateBack({
						delta: 1,
					})
				},1500)

				// wx.request({
				// 	url:url+'wx_commen/user_login',
				// 	method: "GET",
				// 	data:{
				// 		ask_type:'open_id',
				// 		open_id:openid,
				// 		phone:phone,
				// 	},
				// 	success:function(resh){
				// 		console.log("openid",resh);
				// 		if(resh.data.code == "success"){
				// 		}else{
				// 			that.setData({success:true})
				// 		}
				// 	}
				// })
			}
		})
		/* ----请求后台提交成功---- */
		// wx.showToast({
		// 	title: '成功',
		// 	icon: 'success',
		// 	mask: true,
		// 	duration: 1500
		// });
		/* ----请求后台提交成功---- */
	},




})